package tool;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static java.lang.Double.NaN;

public class Maxretrace {


    /**
     * 最大回撤率计算
     * @param list
     * @return
     */
    public static double GetMaxretrace(List<Map<String, String>> list){

        try {

            double max=list.stream().filter(m->m.get("fundvalue")!=null).mapToDouble(m-> Double.parseDouble(m.get("fundvalue"))).summaryStatistics().getMax();
            double min=list.stream().filter(m->m.get("fundvalue")!=null).mapToDouble(m-> Double.parseDouble(m.get("fundvalue"))).summaryStatistics().getMin();

            return (max/min)-1;
        }catch (Exception e){
            System.out.println(e);
        }
        return NaN;
    }

    public static void main(String[] args) {
        List<Map<String, String>> list=new LinkedList<>();
        Map<String, String> map=new HashMap<>();
        map.put("dayup","5");
        Map<String, String> map1=new HashMap<>();
        map1.put("dayup","2");
        list.add(map);
        list.add(map1);

        System.out.println(GetMaxretrace(list));
    }
}
